package restaurant;

import java.util.ArrayList;

/**
 * Represents tab items. This class contains information about a table's tab.
 * 
 * @author Ebonie
 */

public class Tab
{

	/** The tab number. */
	private int tabNo;

	/** The table number for this tab. */
	private int tableNo;

	/** The list of items on this tab. */
	private ArrayList<Integer> items;

	/** The prices of items on this tab. */
	private ArrayList<Double> itemPrices;

	/** Whether or not this tab is being split. The default is {@code false}. */
	private boolean split = false;

	/** Whether or not this tab is open. The default is {@code true}. */
	private boolean open = true;

	/** The number of menu items on this tab. */
	private int numMenuItems;

	/** The number of times this tab is split. */
	private int splitNumber;



	/**
	 * Instantiates a newly created tab.
	 * 
	 * @param tabNo the tab number.
	 * @param tableNo the table number of the tab to be created.
	 */
	public Tab(int tabNo, int tableNo) {
		this.tabNo = tabNo;
		this.tableNo = tableNo;
		items = new ArrayList<Integer>();
		itemPrices = new ArrayList<Double>();
	}



	/**
	 * Gets the tab number. The tab number is used to uniquely identify each
	 * tab.
	 * 
	 * @return the tab number.
	 */
	public int getTabNo()
	{
		return tabNo;
	}



	/**
	 * Gets the table number of this tab.
	 * 
	 * @return the table number.
	 */
	public int getTableNo()
	{
		return tableNo;
	}



	/**
	 * Checks if the tab is being split.
	 * 
	 * @return {@code true} if the tab is being split.
	 */
	public boolean isSplit()
	{
		return split;
	}



	/**
	 * Checks if the tab is open.
	 * 
	 * @return {@code true} if the tab is open.
	 */
	public boolean isOpen()
	{
		return open;
	}



	/**
	 * Gets the number of menu items on this tab.
	 * 
	 * @return the number of items on this tab.
	 */
	public int getNumMenuItems()
	{
		return numMenuItems;
	}



	/**
	 * Sets a tab as being split. This only occurs when the customers at the
	 * table choose to pay the tab separately.
	 * 
	 * @param splitInto the number of times the tab is split.
	 */
	public void split(int splitInto)
	{
		split = true;
		splitNumber = splitInto;
	}



	/**
	 * Closes a previously open. This occurs when a tab has been paid.
	 */
	public void close()
	{
		open = false;
	}



	/**
	 * Adds an item to this tab.
	 * 
	 * @param newItem the item to be added to this tab.
	 * @param newItemPrice the price of the item to be added to this tab.
	 */
	public void addItems(int newItem, double newItemPrice)
	{
		items.add(newItem);
		itemPrices.add(newItemPrice);
	}



	/**
	 * Calculates the total price of this tab.
	 * 
	 * @return the total price of this tab.
	 */
	public double calculateTotal()
	{
		int sum = 0;
		for (Double price : itemPrices)
			sum += price;

		return sum;
	}
}
